// components/amount/index.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    count:{
      type: Number,
      value:1
    }
  },

  /**
   * 组件的初始数据
   */
  data: {

  },

  /**
   * 组件的方法列表
   */
  methods: {
    subtract(e){
      // console.log(1)
      let count = this.data.count
      count>1? count-- : 1
      var myEventDetail = {
        val: count
      }
      this.setData({
        count:count
      })
      this.triggerEvent("myevent", myEventDetail)
      // 点击减号触发
      this.triggerEvent("subevent")
    },
    add(e){
      // console.log(2)
      let count = this.data.count
      var myEventDetail = {
        val: ++count
      }
      this.setData({
        count: count
      })
      this.triggerEvent("myevent", myEventDetail)
      // 点击+号触发
      this.triggerEvent("addevent")
    },
    inputChangeHandle(e){
      // console.log(e)
      var value = e.detail.value
      var myEventDetail = {
        val: value
      }
      // 数据改变时，向父级传递新数据
      this.triggerEvent ("myevent",myEventDetail)
    }
  }
})
